var api = require('../common/config.js')
Page({
  data: { 
    uname:'',
    pwd:''
  },
  loginTap: function(e){
    var that = this;
    console.log(api.login + "---" + that.data.uname + " " + that.data.pwd)
    if(that.data.uname.length < 1){
      wx.showModal({
        title: '错误信息',
        content: '请输入用户名',
        showCancel: false
      });
      return false;
    }
    if (that.data.pwd.length < 1) {
      wx.showModal({
        title: '错误信息',
        content: '请输入密码',
        showCancel: false
      });
      return false;
    }    
    wx.showLoading({
      title: '加载中...',
    });
    wx.request({
      url: api.login,
      data: {
        uname: that.data.uname,
        pwd: that.data.pwd
      },
      method: 'GET',
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        wx.hideLoading()
        res = res.data;
        console.log(res)
        if (res.code == 1) { 
          wx.setStorage({
            key: "data",
            data: res.data,
            success: function () {
              wx.navigateTo({
                url: '/pages/scan1/scan1'
              });
            }
          });
        }
      }
    });
  },
  bindUnameInput: function (e) {
    this.setData({
      uname: e.detail.value
    });
    console.log("uname=" + e.detail.value)
  },
  bindPwdInput: function (e) {
    this.setData({
      pwd: e.detail.value
    });
  }
})
